package com.hiof.moraa.server.controller;

import com.hiof.moraa.server.service.*;
import com.hiof.moraa.server.service.model.GoogleGpsGeoPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Bergy
 */
@Controller
public class GeoTaggedPictureController {

    @Autowired
    MediaService mediaService;
    @Autowired
    UserService userService;
    @Autowired
    FeedService feedService;
    @Autowired
    RouteService routeService;
    @Autowired
    LocationService locationService;

    @RequestMapping({"/geoTagged"})
    public String viewGeoTaggedPicture(
            @RequestParam String username,
            @RequestParam int routeId,
            @RequestParam double lat,
            @RequestParam double lng,
            Map<String, Object> model,
            HttpServletRequest request) {

        String viewName = "";
        model.put("userInfo", userService.getUserInfoByUsernameAndRouteId(username, routeId));
        model.put("feedList", feedService.getLatestFeedsOfOneRoute(routeId));
        model.put("routeId", routeId);

        String serverName = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        model.put("serverName", serverName);

        model.put("athleteLocation", locationService.getLatestLocationOfAthlete(username, routeId));
        model.put("routeMapPath", routeService.getMapPublicPath(routeId));
        model.put("mediaList", mediaService.getAllMediaOfOneAthleteByUsernameAndRouteId(username, routeId));
        model.put("startUpGeoPoint", new GoogleGpsGeoPoint(lat, lng, 0));
        viewName = "profileMap";

        return viewName;
    }
}
